import socket
import threading

HTTP_IP = '127.0.0.1'
HTTP_PORT = 9999


def handle_request(client):
    # client.send('HTTP/1.1 200 OK\r\n\r\n')
    client.send(b'Hello!')
    buf = client.recv(1024)
    print('receive:' + str(buf))
    client.close()


def connect():
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((HTTP_IP, HTTP_PORT))
    # sock.listen(5)

    # while True:
    # connection, address = sock.accpet()
        # threading.Thread(target=handle_request, args=(connection, ))

    handle_request(sock)
    # connection.close()


connect()